import { defHttp } from '/@/utils/http/axios';
import { PageResult } from '@/api/model/pageResult';
import { ContentTypeEnum } from '@/enums/httpEnum';
import { QueryMemberLevelVo } from '@/api/base-data/member-level/model/queryMemberLevelVo';
import { QueryMemberLevelBo } from '@/api/base-data/member-level/model/queryMemberLevelBo';
import { GetMemberLevelBo } from '@/api/base-data/member-level/model/getMemberLevelBo';
import { CreateMemberLevelVo } from '@/api/base-data/member-level/model/createMemberLevelVo';
import { UpdateMemberLevelVo } from '@/api/base-data/member-level/model/updateMemberLevelVo';
import { MemberLevelSelectorBo } from '@/api/base-data/member-level/model/memberLevelSelectorBo';
import { QueryMemberLevelSelectorVo } from '@/api/base-data/member-level/model/queryMemberLevelSelectorVo';

const baseUrl = '/basedata/member-level';
const selectorBaseUrl = '/selector';
const region = 'cloud-api';

export function selector(
  params: QueryMemberLevelSelectorVo,
): Promise<PageResult<MemberLevelSelectorBo>> {
  return defHttp.get<PageResult<MemberLevelSelectorBo>>(
    {
      url: selectorBaseUrl + '/member-level',
      params,
    },
    {
      region,
    },
  );
}

export function loadMember(ids: string[]): Promise<MemberLevelSelectorBo[]> {
  return defHttp.post<MemberLevelSelectorBo[]>(
    {
      url: selectorBaseUrl + '/member-level/load',
      data: ids,
    },
    {
      contentType: ContentTypeEnum.JSON,
      region,
    },
  );
}

/**
 * 查询列表
 * @param params
 * @returns {Promise}
 */
export function query(params: QueryMemberLevelVo): Promise<PageResult<QueryMemberLevelBo>> {
  return defHttp.get<PageResult<QueryMemberLevelBo>>(
    {
      url: baseUrl + '/query',
      params: params,
    },
    {
      region,
    },
  );
}

/**
 * 根据ID查询
 * @param id
 * @returns {Promise}
 */
export function get(id: String): Promise<GetMemberLevelBo> {
  return defHttp.get<GetMemberLevelBo>(
    {
      url: baseUrl,
      params: {
        id,
      },
    },
    {
      region,
    },
  );
}

/**
 * 新增
 * @param params
 * @returns {Promise}
 */
export function create(params: CreateMemberLevelVo): Promise<void> {
  return defHttp.post<void>(
    {
      url: baseUrl,
      data: params,
    },
    {
      contentType: ContentTypeEnum.FORM_URLENCODED,
      region,
    },
  );
}

/**
 * 修改
 * @param params
 * @returns {Promise}
 */
export function update(params: UpdateMemberLevelVo): Promise<void> {
  return defHttp.put<void>(
    {
      url: baseUrl,
      data: params,
    },
    {
      contentType: ContentTypeEnum.FORM_URLENCODED,
      region,
    },
  );
}
